package com.ceba.test.modules.statistic.logicService;


import com.ceba.cebautils.StringUtil;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ceba.test.base.configs.CebaConfig;
import com.ceba.test.modules.sign.logicService.SignLogicService;
import com.ceba.test.modules.statistic.service.CollectSignRAService;
import com.ceba.test.modules.statistic.service.StatisticService;

import abc.IContextDictionary;
import abc.web.HttpContext;
import configs.context.SpringBeans;

import java.util.Map;

public class StatisticLogicService {
	
	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(StatisticLogicService.class);
	
	private SignLogicService signLogicService = SpringBeans.getSignLogicService("signLogicService");
	
	private CollectSignRAService collectSignRAService;
	private  StatisticService statisticService;
	
	//CollectSignRAService 类
	
	/**
	 * 添加一条记录
	 * @return
	 */
	public Boolean add(float count,String date ) throws Exception{
		return collectSignRAService.add(count, date);
	}

	
	/**
	 * 获取所有签名报告数目
	 * @return
	 */
	public  long getAllReportSign() throws Exception{
		String allSc_Rs = CebaConfig.getDecode(CebaConfig.get("ALL_SIGNCOUNT_REPORT"));
		long allSC_R  = StringUtil.isEmptyString(allSc_Rs)?0:Long.valueOf(allSc_Rs);
		long countR = signLogicService.getAllSignReports();
		if(allSC_R==0 ){
			allSC_R = countR;
			CebaConfig.set("ALL_SIGNCOUNT_REPORT", CebaConfig.getEncode(allSC_R+""));
		}
		return allSC_R;
	}
	
	
	/**
	 * 获取所有签名报告数目
	 * @return
	 */
	public  long getAllUserReportSign(String userId,int editionType) throws Exception{
		String allSc_Rs = CebaConfig.getDecode(CebaConfig.get("ALL_SIGNCOUNT_REPORT"));
		long allSC_R  = StringUtil.isEmptyString(allSc_Rs)?0:Long.valueOf(allSc_Rs);
		long countR = signLogicService.getAllSignReports();
		if(allSC_R==0 ){
			allSC_R = countR;
			CebaConfig.set("ALL_SIGNCOUNT_REPORT", CebaConfig.getEncode(allSC_R+""));
		}
		
		
		long countCurUserR = signLogicService.getCusUserAllSignReports(userId,editionType);
		
		
		return countCurUserR;
	}
	
	/**
	 * 获取所有今年签名报告数目
	 * @return
	 */
	public  long getYearReportSign() throws Exception{
		String ySc_Rs = CebaConfig.getDecode(CebaConfig.get("YEAR_SIGNCOUNT_REPORT"));
		long YSC_R =StringUtil.isEmptyString(ySc_Rs)?0:Long.valueOf(ySc_Rs);
		long countYR = signLogicService.getYearSignReports();
		if(YSC_R==0 ){
			YSC_R = countYR;
			CebaConfig.set("YEAR_SIGNCOUNT_REPORT",  CebaConfig.getEncode(YSC_R+""));
		}
		return YSC_R;
	}
	
	/**
	 * 获取前一天签名报告数目
	 * @return
	 */
	public  long getLastDayReportSign() throws Exception{
		return signLogicService.getLastDayReportSign();
	}
	/**
	 * 获取所有签名附件数目
	 * @return
	 */
	public  long getAllAttachSign()throws Exception{
		String allSc_As = CebaConfig.getDecode(CebaConfig.get("ALL_SIGNCOUNT_ATTACH"));
		long allSC_A =  StringUtil.isEmptyString(allSc_As)?0:Long.valueOf(allSc_As);
		long countAR = signLogicService.getAllSignOReports();
		if(allSC_A==0 ){
			allSC_A = countAR;
			CebaConfig.set("ALL_SIGNCOUNT_ATTACH",  CebaConfig.getEncode(allSC_A+""));
		}
		return allSC_A;
	}
	/**
	 * 获取所有今年签名附件数目
	 * @return
	 */
	public  long getYearAttachSign()throws Exception{
		String ySc_As = CebaConfig.getDecode(CebaConfig.get("YEAR_SIGNCOUNT_ATTACH"));
		long YSC_A = StringUtil.isEmptyString(ySc_As)?0:Long.valueOf(ySc_As);
		long countYAR = signLogicService.getYearSignOReports();
		if(YSC_A==0  ){
			YSC_A = countYAR;
			CebaConfig.set("YEAR_SIGNCOUNT_ATTACH", CebaConfig.getEncode( YSC_A+""));
		}
		return YSC_A;
	}
	
	/**
	 * 获取前一天签名附件数目
	 * @return
	 */
	public  long getLastDayAttachSign(){
		return signLogicService.getLastDayAttachSign();
	}
	
	
	//StatisticService 类
	
	public String statisticSignForDownLoad(String userId, Map<String,Object> dic) {
		return statisticService.statisticSignForDownLoad(userId, dic);
	}
	
	
	public int getAllStatistisCount(String startTime,String endTime,String key) throws Exception{
		return statisticService.getAllStatistisCount(startTime, endTime, key);
	}
	
	public String statisticSign(HttpContext context, IContextDictionary dic){
		return statisticService.statisticSign(context, dic);
	}
	
	public CollectSignRAService getCollectSignRAService() {
		return collectSignRAService;
	}

	public void setCollectSignRAService(CollectSignRAService collectSignRAService) {
		this.collectSignRAService = collectSignRAService;
	}

	public StatisticService getStatisticService() {
		return statisticService;
	}

	public void setStatisticService(StatisticService statisticService) {
		this.statisticService = statisticService;
	}

	public void signTest(int count) throws  Exception{
		signLogicService.signTest(count);
	}
	public int queryFileCount(int count) throws  Exception{
		return signLogicService.queryFileCount(count);
	}


}
